package com.yanqu.road.server.cmd.activity.summergames;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SummerGamesProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.activity.summergames.CrossSummerGamesActivity;
import com.yanqu.road.server.manager.activity.summergames.CrossSummerGamesMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_SUMMER_GAMES_EXCHANGE_APPLY, desc = "提交交换请求")
public class CrossSummerGamesApplyExchangeCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        SummerGamesProto.CrossSummerGamesApplyExchangeReqMsg reqMsg = SummerGamesProto.CrossSummerGamesApplyExchangeReqMsg.parseFrom(packet.getBytes());
        int activityId = reqMsg.getActivityId();
        CrossSummerGamesActivity activity = CrossSummerGamesMgr.getActivity(activityId);
        if(activity != null){
            UserBaseInfo userBaseInfo = PlayerBasePb.parseToUserBaseInfo(reqMsg.getUserData().getPlayerBaseData());
            CrossUserMgr.updateUserBaseInfo(packet.getPlayerId(), userBaseInfo);
            activity.applyExchange(serverId, packet.getPlayerId(), reqMsg.getWantId(), reqMsg.getPayId(), reqMsg.getAppUserId(), reqMsg.getAppUserServerId(), reqMsg.getUnion(), userBaseInfo.getNickName());
        }
    }

    @Override
    public void sendData() {

    }
}
